#include "Blob.h"


Blob::Blob(void)
{
	clear();
}


Blob::~Blob(void)
{
}

void Blob::addPixel(int x, int y)
{
	pixelCount++;
	sumX += x;
	sumY += y;

	// compute extents
	if(x < leftExtent)
		leftExtent = x;
	if(x > rightExtent)
		rightExtent = x;
	if(y < topExtent)
		topExtent = y;
	if(y > bottomExtent)
		bottomExtent = y;
}

void Blob::clear()
{
	pixelCount = 1;
	sumX = 0;
	sumY = 0;

	// initial measures
	leftExtent = 30000;
	rightExtent = -1;
	topExtent = 30000;
	bottomExtent = -1;

}

int Blob::getHeight()
{
	height = bottomExtent - topExtent;

	return height;
}

int Blob::getWidth()
{
	width = rightExtent - leftExtent;

	return width;
}

int Blob::getCOMX()
{
	return (sumX / pixelCount);
}

int Blob::getCOMY()
{
	return (sumY / pixelCount);
}

double Blob::getRatio()
{
	return (double)getHeight()/getWidth();
}
